#include <iostream>
#include <fstream>
#include <string>

class FileReader {
public:
    FileReader(const std::string &filename) {
        file.open(filename);
        if (!file.is_open()) {
            throw std::runtime_error("Failed to open file");
        }
    }

    ~FileReader() {
        if (file.is_open()) {
            file.close();
        }
    }

    void readFile() {
        std::string line;
        while (std::getline(file, line)) {
            std::cout << line << std::endl;
        }
    }

private:
    std::ifstream file;
};

int main() {
    try {
        FileReader fr("example.txt");
        fr.readFile();
    } catch (const std::exception &e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }

    return 0;
}
